/**
* Copyright (c) 2012-2013 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation. 
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners. 
* See LICENSE.TXT for license information.
*/

package com.nokia.example.explonoid.effects;

import javax.microedition.lcdui.Graphics;

/**
 * Paints a shock wave effect on a Graphics object. 
 * <P>
 * Triggered when e.g. the ball hits a wall or the player 
 * taps the screen. For usage, see the ShockWaveManager class.
 * 
 * @see com.nokia.example.explonoid.effects.ShockWaveManager
 */
public class ShockWave {

    private int maxSize = 100;
    private int frames = 6;
    private int frame = 1;
    private int x = 0;
    private int y = 0;

    public ShockWave(int x, int y, int size, int frames) {
        this.x = x;
        this.y = y;
        this.maxSize = size;
        this.frames = frames;
    }

    public boolean paint(Graphics g) {
        int width = (int) (frame * maxSize / frames + 0.5);
        int height = (int) (0.5 * frame * maxSize / frames + 0.5);
        g.setColor(0x88FFFFFF);
        g.drawArc(x - width / 2, y - height / 2, width, height, 0, 360);
        if (frame < frames) {
            frame++;
            return true;
        }
        else {
            return false;
        }
    }
}
